/*
 * Copyright 2013 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package com.madding.shared.encrypt.cert.bc.main;

import static com.madding.shared.encrypt.cert.gen.BCCertGenerator.*;

import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;

import com.madding.shared.encrypt.cert.bc.CertFilePersistence;
import com.madding.shared.encrypt.cert.bc.util.KeyPairUtil;

/**
 * 类AlilangCACreator.java的实现描述：TODO 类实现描述
 * 
 * @author madding.lip Dec 6, 2013 9:23:41 PM
 */
public class AlilangCACreator {

    public static final long ROOT_CERT_INDATE = 20 * 365 * 24 * 60L * 60 * 1000L;

    public static void main(String[] args) throws Exception {

        String CA = "/home/madding/output/alilang_ca";
        String CLIENT_CA = "/home/madding/output/alilang_client_ca";
        // create alilang ca
        KeyPair caKeyPair = KeyPairUtil.generateRSAKeyPair();
        Certificate caCert = getIns().createCaCert(caKeyPair);
        Certificate[] caChain = new Certificate[1];
        caChain[0] = caCert;
        CertFilePersistence.storeCertFile("alilang_ca", caChain, caKeyPair, CA);
        System.out.println("alilang ca created end....");

        // create aliliang client ca
        PrivateKey caPrivKey = caKeyPair.getPrivate();
        KeyPair intKeyPair = KeyPairUtil.generateRSAKeyPair();

        Certificate clientCaCert = getIns().createClientCaCert(intKeyPair, caPrivKey, (X509Certificate) caCert);
        Certificate[] clientCaChain = new Certificate[2];
        clientCaChain[0] = clientCaCert;
        clientCaChain[1] = caCert;
        CertFilePersistence.storeCertFile("alilang_client_ca", clientCaChain, intKeyPair, CLIENT_CA);
        System.out.println("alilang client ca created end....");
    }
}
